'use strict';

angular.module('myApp.register', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/register', {
    templateUrl: 'views/register/register.html',
    controller: 'RegisterCtrl'
  });
}])

.controller('RegisterCtrl', function($scope, $http) {

  $scope.name = '';
  $scope.email = '';
  $scope.password = '';
  $scope.password_confirmation = '';



	$scope.register = function(name,email,password,password_confirmation) {

		var body = 
		{ 
    		"user": { 
            		"name": name,
            		"email": email, 
            		"password": password, 
            		"password_confirmation":password_confirmation
			} 
		}

    console.log('Attempting to signup with' + JSON.stringify(body));

		$http.post('http://localhost:3000/api/v1/signup',body)
		.success(function(data, status, headers, config) {
    		console.log(status + ' ' + JSON.stringify(data));
    		$scope.message = data.message;
        $scope.errors = [];
  		})
  		.error(function(data, status, headers, config) {
    		console.log(status + ' ' + JSON.stringify(data));
    		$scope.message = data.message;
        $scope.errors = data.errors;
  		});
	};
});